/*
 * @Author: jipeng.Li
 * @Date: 2020-01-23 17:32:41
 * @LastEditors: 汪滔
 * @LastEditTime: 2021-07-22 16:41:02
 * @Description: file content
 */

import React, { Component } from 'react';
import {
  Keyboard,
  Modal,
  PixelRatio,
  StyleSheet,
  Text,
  TextInput,
  TouchableOpacity,
  View,
  Platform
} from 'react-native';
import {
  fontColorBlack,
  fontColorSecDeepGray,
  mainBgColorLightGray,
  mainBgColorWhite,
  px2dp,
  screenHeight,
  screenWidth,
  splitLineColorLightGray,
} from '@/styles';
import { Button } from '@/common';

const { Submit } = Button;

export default class ModalBox extends Component {
  constructor(props) {
    super(props);
    this.state = {
      keyboardHeight: 0,
    };
  }

  componentDidMount() {

  }

  componentWillMount() {
    // this.keyboardDidShowListener = Keyboard.addListener('keyboardDidShow', event => {
    //   this._keyboardDidShow(event);
    // });
    // this.keyboardDidHideListener = Keyboard.addListener('keyboardDidHide', event => {
    //   this._keyboardDidHide(event);
    // });
  }

  componentWillUnmount() {
    // this.keyboardDidShowListener.remove();
    // this.keyboardDidHideListener.remove();
  }

  render() {
    const {
      isShow = false,
      driverPhone,
      changePhone = () => {},
      determine = () => {},
      changeIsShow = () => {}
    } = this.props;
    const { keyboardHeight } = this.state;
    return (
      <Modal
        animationType='slide'
        transparent
        visible={isShow}
        onRequestClose={() => {
          changeIsShow(false);
        }}
        onShow={() => {}}
      >
        <TouchableOpacity
          style={styles.mask}
          onPress={() => {
            changeIsShow(false);
          }}
        />
        <View
          style={[styles.infoContainer]}
        >
          <View style={styles.header}>
            <TouchableOpacity
              style={styles.cancel}
              onPress={() => {
                changeIsShow(false);
              }}
            >
              <Text
                style={{
                  fontSize: px2dp(32),
                  color: fontColorSecDeepGray }}
              >
                取消
              </Text>
            </TouchableOpacity>
            <Text
              style={{
                fontSize: px2dp(32),
                color: fontColorBlack,
                fontWeight: 'bold',
              }}
            >
              新增司机
            </Text>
            <Submit
              text='确定'
              boxStyle={{
                width: px2dp(104),
                height: px2dp(60),
                borderRadius: px2dp(8),
                position: 'absolute',
                right: px2dp(28),
              }}
              disabled={false}
              onClick={() => {
                determine();
              }}
            />
          </View>
          <View style={{ height: px2dp(400) }}>
            <View
              style={{
                marginTop: px2dp(100),
                flexDirection: 'row',
                alignItems: 'center',
                paddingHorizontal: px2dp(50)
              }}
            >
              <Text
                style={{
                  height: px2dp(40),
                  width: px2dp(80),
                  color: '#343332',
                  fontSize: px2dp(28),
                }}
              >
                司机
              </Text>
              <View style={styles.textInputContainer}>
                <TextInput
                  style={styles.textInputWrap}
                  placeholder='请输入司机电话号码'
                  placeholderTextColor='#CDCCC9'
                  multiline
                  maxLength={11}
                  defaultValue=''
                  value={driverPhone}
                  underlineColorAndroid='transparent'
                  keyboardType='numeric'
                  onChangeText={text => {
                    const newText = text.replace(/[^\d]+/, '');
                    changePhone(newText);
                  }}
                />
              </View>
            </View>
          </View>
        </View>
      </Modal>
    );
  }

  _keyboardDidShow = (e) => {
    console.log(e);
    this.setState({
      keyboardHeight: e.endCoordinates.height,
    });
  }

  _keyboardDidHide = (e) => {
    this.setState({
      keyboardHeight: 0,
    });
  }

  // 提交
  submit = () => {

  };
}
const styles = StyleSheet.create({
  container: {
    flex: 1,
    alignItems: 'center',
    backgroundColor: mainBgColorLightGray,
    justifyContent: 'center',
  },
  mask: {
    width: screenWidth,
    height: screenHeight,
    backgroundColor: 'rgba(0,0,0,0.2)',
    position: 'absolute',
    left: 0,
    top: 0,
  },
  infoContainer: {
    width: screenWidth,
    maxHeight: 0.5 * screenHeight,
    backgroundColor: mainBgColorWhite,
    position: 'absolute',
    bottom: 0,
    left: 0,
    borderRadius: px2dp(12),
    overflow: 'hidden',
    zIndex: 10,
  },
  header: {
    width: screenWidth,
    height: px2dp(108),
    justifyContent: 'center',
    alignItems: 'center',
    borderBottomWidth: 1 / PixelRatio.get(),
    borderColor: splitLineColorLightGray,
  },
  cancel: {
    position: 'absolute',
    left: 0,
    top: 0,
    width: 80,
    height: '100%',
    justifyContent: 'center',
    alignItems: 'center',
  },
  textInputContainer: {
    flex: 1,
    height: px2dp(88),
    flexDirection: 'row',
    alignItems: 'center',
    backgroundColor: mainBgColorLightGray,
    borderRadius: px2dp(12),
    paddingHorizontal: px2dp(10)
  },
  textInputWrap: {
    flex: 1,
    // lineHeight: px2dp(88),
    fontSize: px2dp(32),
    backgroundColor: mainBgColorLightGray,
    color: fontColorBlack,
  },
});
